package com.flowable.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.flowable.domain.dto.SysDeployForm;
import com.flowable.domain.dto.SysForm;
import com.flowable.service.ISysDeployFormService;
import com.flowable.service.ISysFormService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 流程表单Controller
 *
 * @author Tony
 * @date 2021-04-03
 */
@RestController
@RequestMapping("/flowable/sysform")
public class SysFormController {
    @Autowired
    private ISysFormService SysFormService;

    @Autowired
    private ISysDeployFormService sysDeployFormService;

    /**
     * 查询流程表单列表
     */
    @GetMapping("/list")
    @ApiOperation(value = "查询流程表单列表接口")
    public ResponseEntity list(Page pageDto, SysForm sysForm) {
        return SysFormService.selectSysFormList(pageDto, sysForm);
    }

    @GetMapping("/formList")
    public ResponseEntity formList(Page pageDto, SysForm sysForm) {
        return SysFormService.selectSysFormList(pageDto, sysForm);
    }

    @ApiOperation("通过表单编号获取表单名称集合接口")
    @PostMapping("/getLableByIds")
    public ResponseEntity  getLableByIds(@RequestBody List<String> ids){
        return SysFormService.getLableByIds(ids);
    }
//    /**
//     * 导出流程表单列表
//     */
//    @PreAuthorize("@ss.hasPermi('flowable:form:export')")
//    @GetMapping("/export")
//    public ResponseEntity export(SysForm sysForm) {
//        List<SysForm> list = SysFormService.selectSysFormList(sysForm);
//        ExcelUtil<SysForm> util = new ExcelUtil<SysForm>(SysForm.class);
//        return util.exportExcel(list, "form");
//    }

    /**
     * 获取流程表单详细信息
     */
    @GetMapping(value = "/{formId}")
    @ApiOperation(value = "获取流程表单详细信息接口")
    public ResponseEntity getInfo(@PathVariable("formId") Long formId) {
        return ResponseEntity.ok(SysFormService.selectSysFormById(formId));
    }

    @PostMapping("/save")
    @ApiOperation(value = "修改流程表单接口")
    public ResponseEntity save(@RequestBody SysForm sysForm) {
        return ResponseEntity.ok(SysFormService.save(sysForm));
    }

    /**
     * 删除流程表单
     */
    @DeleteMapping("/del")
    @ApiOperation(value = "删除流程表单接口")
    public ResponseEntity remove(@RequestBody List<Long> ids) {
        return SysFormService.deleteSysFormByIds(ids.toArray(new Long[ids.size()]));
    }


    /**
     * 挂载流程表单
     */
    @PostMapping("/addDeployForm")
    @ApiOperation(value = " 挂载流程表单接口")
    public ResponseEntity addDeployForm(@RequestBody SysDeployForm sysDeployForm) {
        return sysDeployFormService.insertSysDeployForm(sysDeployForm);
    }

}
